package pl.omega.selenium.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class FilmAddPage extends InternalPage {

	public FilmAddPage(PageManager pages) {
		super(pages);
	}

	public FilmAddPage ensurePageLoaded() {
		super.ensurePageLoaded();
		wait.until(presenceOfElementLocated(By.id("imdbsearchform")));
		return this;
	}

	@FindBy(name = "name")
	private WebElement nameField;

	@FindBy(name = "year")
	private WebElement yearField;

	@FindBy(id = "submit")
	private WebElement submitButton;

	public FilmAddPage setName(String name) {
		nameField.sendKeys(name);
		return this;
	}

	public FilmAddPage setYear(String year) {
		yearField.sendKeys(year);
		return this;
	}

	public InternalPage clickSubmitButton() {
		submitButton.click();
		return pages.internalPage;
	}
}
